package com.broad.commerce.code.common;

import cn.hutool.core.io.FileUtil;
import org.apache.commons.io.filefilter.AbstractFileFilter;
import org.apache.commons.io.filefilter.IOFileFilter;

import java.io.File;
import java.io.Serializable;

/**
 * @author stephen
 * @version V1.0
 * @date 2022-04-17 11:02
 * @description: NotDotFileFilter
 **/
public class NotDotFileFileFilter extends AbstractFileFilter implements Serializable {

	public static final IOFileFilter INSTANCE = new NotDotFileFileFilter();
	private static final long serialVersionUID = 7766075220177672851L;

	/**
	 * Restrictive constructor.
	 */
	protected NotDotFileFileFilter() {
	}

	/**
	 * Checks to see if the file is a file.
	 * @param file the File to check
	 * @return true if the file is a file
	 * 文件名称不含 "." 以及父文件夹名称也不含有 "."
	 */
	@Override
	public boolean accept(final File file) {
		for (int i = 0; i < 4; i++) {
			File parent = FileUtil.getParent(file, i);
			if (parent != null && parent.getName().startsWith(".")) {
				return false;
			}
		}
		return file.isFile();
	}
}
